package org.pupil.event;

import org.pupil.common.Cache;
import org.pupil.common.Host;
import org.pupil.common.Service;
import org.pupil.common.URL;

/**
 * @Description: 服务销毁事件的监听执行器
 * @Author: pupil
 * @Date: 2024/07/10 下午 9:18
 */
public class DestroyRpcListener implements IRpcListener<DestroyRpcEventData> {
    @Override
    public void exec(DestroyRpcEventData destroyEventData) {
        final URL url = (URL) destroyEventData.getData();
        final Service serviceName = new Service(url.getServiceName(),url.getVersion());
        // 判断服务是否存在，存在则销毁服务中对应的客户端资源定位器
        if (Cache.SERVICE_URLS.containsKey(serviceName)){
            Cache.SERVICE_URLS.get(serviceName).remove(url);
        }
        final Host host = new Host(url.getIP(), url.getPort());
        if (Cache.CHANNEL_FUTURE_MAP.containsKey(host)) {
            Cache.CHANNEL_FUTURE_MAP.remove(host);
        }
    }
}
